import { onMounted, ref } from 'vue'
import { getHospitalAPI } from '@/api/home'
import { Content, HospitalResponseData } from '@/api/home/type'

export function useHospital() {
    onMounted(() => {
        getHospital()
    })
    const getHospital = async () => {
        let res: HospitalResponseData = await getHospitalAPI(currentPage.value, pageSize.value, hostype.value, districtCode.value)
        hospitalArr.value = res.data.content
        totalNum.value = res.data.totalElements
    }
    const getLevel = (level: string) => {
        hostype.value = level
        getHospital()
    }
    const getRegion = (region: string) => {
        districtCode.value = region
        getHospital()
    }

    let pageSize = ref<number>(6)
    let currentPage = ref<number>(1)
    let totalNum = ref<number>(100)
    let hospitalArr = ref<Content>([])
    let hostype = ref<string>('')
    let districtCode = ref<string>('')

    return {
        pageSize, currentPage, totalNum, hospitalArr,
        getHospital, getLevel, getRegion
    }
}